//添加cookie
function setCookie(key, value, time1 = 0, path = '/') {
    if (time1) {
        //设置存储时间
        var t1 = new Date() - 8 * 3600 * 1000 + time1 * 1000
        var tt = new Date(t1)
        //设置cookie的键值对
        document.cookie = `${key}=${value};expires=${tt};path=${path} `
    } else {
        document.cookie = `${key}=${value};path=${path}`
    }
}

//获取指定cookie
function getCookie(key) {
    //获取所有cookie
    var str1 = document.cookie
    //分割当前字符串
    var ar1 = str1.split('; ')
    //遍历数组每个元素
    for (var i = 0; i < ar1.length; i++) {
        //继续分割数组元素（字符串）
        var ar2 = ar1[i].split('=')
        //判断当前数组的第一个元素是否等于传入key
        if (ar2[0] === key) {
            return ar2[1]
        }
    }
}

//删除指定cookie
function delCookie(key, t1 = -1) {
    setCookie(key, '', t1)
}